﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Input
{
    class Input
    {
        public int position = 1;
        public int card = 1;
        bool keyPress = true;
        public bool inHand = true;
        public int cardSelection;

        #region Board Input
        public void GetBoardInput()
        {
            // Get input state.
            KeyboardState keyboardState = Keyboard.GetState();

            #region Left Key
            //Left key press
            if (keyboardState.IsKeyDown(Keys.Left) && keyPress && position >= 1)
            {
                //Checks to see if position is at the left edge, if it is it wraps to right side
                if (position == 1 || position == 11 || position == 21 || position == 31 || 
                        position == 41 || position == 51 || position == 61 || position == 71 || 
                        position == 81 || position == 91)
                {
                    position += 9;
                }
                else
                {
                    position -= 1;
                }

                keyPress = false;
            }
            #endregion

            #region Right Key
            //Right key press
            if (keyboardState.IsKeyDown(Keys.Right) && keyPress && position <= 100)
            {
                //Checks to see if position is at the right edge, if it is it wraps to the left side
                if (position == 10 || position == 20 || position == 30 || position == 40 ||
                        position == 50 || position == 60 || position == 70 || position == 80 ||
                        position == 90 || position == 100)
                {
                    position -= 9;
                }
                else
                {
                    position += 1;
                }

                keyPress = false;
            }
            #endregion

            #region Up Key
            //Up key press
            if (keyboardState.IsKeyDown(Keys.Up) && keyPress)
            {
                //Checks to see if position is at the top edge, if it is it wraps to the bottom edge
                if (position == 1 || position == 2 || position == 3 || position == 4 ||
                        position == 5 || position == 6 || position == 7 || position == 8 ||
                        position == 9 || position == 10)
                {
                    position += 90;
                }
                else
                {
                    position -= 10;
                }

                keyPress = false;
            }
            #endregion

            #region Down Key
            //Down key press
            if (keyboardState.IsKeyDown(Keys.Down) && keyPress)
            {
                //Checks to see if position is at the bottom edge, if it is it wraps to the top edge
                if (position == 91 || position == 92 || position == 93 || position == 94 ||
                        position == 95 || position == 96 || position == 97 || position == 98 ||
                        position == 99 || position == 100)
                {
                    position -= 90;
                }
                else
                {
                    position += 10;
                }

                keyPress = false;
            }
            #endregion

            if (keyboardState.IsKeyDown(Keys.A))
            {
                inHand = true;
                keyPress = false;
            }

            #region Key Press Reset
            if (keyboardState.IsKeyUp(Keys.Left) && keyboardState.IsKeyUp(Keys.Right) &&
                    keyboardState.IsKeyUp(Keys.Up) && keyboardState.IsKeyUp(Keys.Down) && !keyPress)
            {
                keyPress = true;
            }
            #endregion
        }
#endregion

        #region Hand Input
        public void GetHandInput()
        {
            // Get input state.
            KeyboardState keyboardState = Keyboard.GetState();

            #region Left Key
            if (keyboardState.IsKeyDown(Keys.Left) && keyPress && card >= 1)
            {
                if (card == 1)
                {
                    card = 6;
                }
                else
                {
                    card -= 1;
                }

                keyPress = false;
            }
            #endregion

            #region Right Key
            if (keyboardState.IsKeyDown(Keys.Right) && keyPress && card <= 6)
            {
                if (card == 6)
                {
                    card = 1;
                }
                else
                {
                    card += 1;
                }

                keyPress = false;
            }
            #endregion

            if (keyboardState.IsKeyDown(Keys.B) && keyPress)
            {
                cardSelection = card;
                inHand = false;
                keyPress = false;
            }

            #region Key Press Reset
            if(keyboardState.IsKeyUp(Keys.Left) && keyboardState.IsKeyUp(Keys.Right) && keyboardState.IsKeyUp(Keys.A))
            {
                keyPress = true;
            }
            #endregion
        }
        #endregion
    }
}